/*
ID: simplyz2
LANG: C
TASK: gift1
*/
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define MAX_LEN 15
#define MAX_NUM 10
struct Person {
	char name[MAX_LEN];
	int amount, index;
} persons[MAX_NUM];
int num;

int
compare(const void *arg1, const void *arg2)
{
	return strcmp(((struct Person *)arg1)->name, ((struct Person *)arg2)->name);
}

int
restore_cmp(const void *arg1, const void *arg2)
{
	return ((struct Person *)arg1)->index - ((struct Person *)arg2)->index;
}

void
solve()
{
	int i, j, t, p, gift, left;
	struct Person tmp;
	struct Person *ptr;
	for(i=0; i<num; i++) {
		scanf("%s", persons[i].name);
		persons[i].amount = 0;
		persons[i].index = i;
	};
	qsort(persons, num, sizeof(struct Person), compare);
	for(i=0; i<num; i++) {
		scanf("%s", tmp.name);
		scanf("%d %d", &t, &p);
		gift = (p==0) ? 0 : (t/p);
		left = (p==0) ? t : (t%p);
		ptr = bsearch(&tmp, persons, num, sizeof(struct Person), compare);
		ptr->amount -= t;
		ptr->amount += left;
		for(j=0; j<p; j++) {
			scanf("%s", tmp.name);
			ptr = bsearch(&tmp, persons, num, sizeof(struct Person), compare);
			ptr->amount += gift;
		}
	}
	qsort(persons, num, sizeof(struct Person), restore_cmp);

	for(i=0; i<num; i++)
		printf("%s %d\n", persons[i].name, persons[i].amount);
}

int
main(int argc, char **argv)
{
	freopen("gift1.in", "r", stdin);
	freopen("gift1.out", "w", stdout);
	while(scanf("%d", &num) != EOF) {
		solve();
	}
	exit(0);
}
